<?php if (!defined('THINK_PATH')) exit(); /*a:3:{s:95:"D:\PHPTutorial\WWW\east_environmental\public/../application/admin\view\news\newsModifyPage.html";i:1547450858;s:77:"D:\PHPTutorial\WWW\east_environmental\application\admin\view\common\head.html";i:1545810378;s:79:"D:\PHPTutorial\WWW\east_environmental\application\admin\view\common\footer.html";i:1545810378;}*/ ?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>东方环保</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/admin/layui/css/layui.css">
    <link rel="stylesheet" href="/static/admin/build/css/app.css" media="all">
</head>
<style>
    .hidden{
        display: none;
    }

</style>
<div style="overflow-x: hidden;width: 96%;margin: auto;padding-top: 1rem;height: 750px">


    <div class="layui-form" action="" method="post">
        <div class="layui-form-item">
            <label class="layui-form-label">文章标题</label>
            <div class="layui-input-inline">
                <input type="hidden" name="id" value="<?php echo (isset($info['id']) && ($info['id'] !== '')?$info['id']:''); ?>">
                <input type="text" name="title" value="<?php echo (isset($info['title']) && ($info['title'] !== '')?$info['title']:''); ?>" placeholder="请输入文章标题"  lay-verify="title" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">文章描述</label>
            <div class="layui-input-block">
                <input type="text" name="desc" value="<?php echo (isset($info['desc']) && ($info['desc'] !== '')?$info['desc']:''); ?>"  placeholder="请输入文章描述" lay-verify="title" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">标题图片</label>
            <div class="layui-input-inline">
                <div class="layui-upload-drag" id="upload_title">
                    <i class="layui-icon"></i>
                    <p>点击上传，或将文件拖拽到此处</p>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">标题图片</label>
            <div class="layui-input-inline">
                <div><img src="<?php echo (isset($info['title_img']) && ($info['title_img'] !== '')?$info['title_img']:''); ?>" class="title_img"></div>
            </div>
        </div>
        <!--<div class="layui-form-item">-->
            <!--<label class="layui-form-label">内容图片</label>-->
            <!--<div class="layui-input-inline">-->
                <!--<div class="layui-upload-drag" id="upload_content">-->
                    <!--<i class="layui-icon"></i>-->
                    <!--<p>点击上传，或将文件拖拽到此处</p>-->
                <!--</div>-->
            <!--</div>-->
        <!--</div>-->
        <!--<div class="layui-form-item">-->
            <!--<label class="layui-form-label">内容图片</label>-->
            <!--<div class="layui-input-inline">-->
                <!--<div><img src="<?php echo (isset($info['content_img']) && ($info['content_img'] !== '')?$info['content_img']:''); ?>" class="content_img"></div>-->
            <!--</div>-->
        <!--</div>-->
        <div class="layui-form-item">
            <label class="layui-form-label">原文章内容</label>
            <div class="layui-input-inline" style="width: 100%;height: 300px">
                <textarea id="demo" name="content" lay-verify="content"><?php echo (isset($info['content']) && ($info['content'] !== '')?$info['content']:''); ?></textarea>
            </div>
        </div>
        <div class="layui-form-item" style="margin-top: 5rem">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="demo1">提交</button>
            </div>
        </div>
    </div>


</div>
<script src="/static/admin/layui/layui.js"></script>
<script src="/static/common/js/jquery.min.js"></script>
<script>
//    图片放大显示
    $('.select_img').on('click',function () {
        var img_url=$(this).data('content');
        layer.open({
            type: 1,
            title: false,
            closeBtn: 0,
            area: ['50%','80%'],
            skin: 'layui-layer-nobg', //没有背景色
            shadeClose: true,
            content: '<img src="'+img_url+'" />',
        });
    })
    //文件上传
    layui.use('upload', function(){
        var $ = layui.jquery
            ,upload = layui.upload;
        //多文件列表示例
        var demoListView = $('#demoList')
            ,uploadListIns = upload.render({
            elem: '#testList'
            ,url: '<?php echo url("Upload/file_images"); ?>'
            ,accept: 'file'
            ,multiple: true
            ,auto: false
            ,bindAction: '#testListAction'
            ,choose: function(obj){
                var files = obj.pushFile(); //将每次选择的文件追加到文件队列
                //读取本地文件
                obj.preview(function(index, file, result){
                    var tr = $(['<tr id="upload-'+ index +'">'
                        ,'<td>'+ file.name +'</td>'
                        ,'<td>'+ (file.size/1014).toFixed(1) +'kb</td>'
                        ,'<td>等待上传</td>'
                        ,'<td>'
                        ,'<button class="layui-btn layui-btn-mini demo-reload layui-hide">重传</button>'
                        ,'<button class="layui-btn layui-btn-mini layui-btn-danger demo-delete">删除</button>'
                        ,'</td>'
                        ,'</tr>'].join(''));

                    //单个重传
                    tr.find('.demo-reload').on('click', function(){
                        obj.upload(index, file);
                    });

                    //删除
                    tr.find('.demo-delete').on('click', function(){
                        delete files[index]; //删除对应的文件
                        tr.remove();
                    });

                    demoListView.append(tr);
                });
            }
            ,done: function(res, index, upload){
                if(res.code == 200){ //上传成功
                    var tr = demoListView.find('tr#upload-'+ index)
                        ,tds = tr.children();
                    tds.eq(2).html('<span style="color: #5FB878;">上传成功</span><input type="hidden" name="images['+index+']" value="'+res.data.src+'">');
                    tds.eq(3).html(''); //清空操作
                    delete files[index]; //删除文件队列已经上传成功的文件
                    return;
                }
                this.error(index, upload);
            }
            ,error: function(index, upload){
                var tr = demoListView.find('tr#upload-'+ index)
                    ,tds = tr.children();
                tds.eq(2).html('<span style="color: #FF5722;">上传失败</span>');
                tds.eq(3).find('.demo-reload').removeClass('layui-hide'); //显示重传
            }
        });

        //普通图片上传 单图片上传
        var uploadInst = upload.render({
            elem: '#image'
            ,url: '<?php echo url("Upload/file_images"); ?>'
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#show_image').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){
                //如果上传失败
                if(res.code == 400){
                    return layer.msg('上传失败');
                }
                $('.value_image').val(res.data.src);
                //上传成功
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
        });
    });
</script>

<script>
    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate;
        //
        // //日期
        // laydate.render({
        //     elem: '#date'
        // });
        // laydate.render({
        //     elem: '#date1'
        // });
        //
        // //创建一个编辑器
        layedit.set({
            uploadImage:{
                url:'<?php echo url("admin/Upload/editUpload"); ?>',
                type:'post'
            }
        });
        var editIndex = layedit.build('demo', {
                tool: [
                    'strong' //加粗
                    ,'italic' //斜体
                    ,'underline' //下划线
                    ,'del' //删除线

                    ,'|' //分割线

                    ,'left' //左对齐
                    ,'center' //居中对齐
                    ,'right' //右对齐
                    ,'image'
                ],
            });
        //
        //自定义验证规则
        form.verify({
            pass: []
            ,content: function(value){
                layedit.sync(editIndex);
            }
        });

        // //监听指定开关
        // form.on('switch(switchTest)', function(data){
        //     layer.msg('开关checked：'+ (this.checked ? 'true' : 'false'), {
        //         offset: '6px'
        //     });
        //     layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
        // });



        //监听提交
        var url='<?php echo url("admin/News/newsModify"); ?>';
        form.on('submit(demo1)', function(data){
            data.field.title_img = $('.title_img').attr('src');
            // data.field.content_img = $('.content_img').attr('src');
            // alert(data.field.content);
            $.post(url,data.field,function (obj) {
                if(obj.code==200){
                    parent.layer.msg(obj.msg, {icon: 6,time: 1000});
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index,data.field); //再执行关闭
                }
                if(obj.code==400){
                    parent.layer.msg(obj.msg, {icon: 5,time: 1000});
                }
            },"JSON");
        });


    });
</script>
<script>
    layui.use('upload', function(){
        var upload = layui.upload;
        //执行实例
        var uploadInst = upload.render({
            elem: '#upload_title' //绑定元素
            ,url: '<?php echo url("Upload/file_images"); ?>' //上传接口
            ,done: function(res){
                //上传完毕回调
                if(res.code == 200){
                    $('.title_img').attr('src',res.data.src)

                }
            }
            ,accept: ''
            ,error: function(res){
                //请求异常回调
                console.log(res)
            }
        });
    });
    layui.use('upload', function(){
        var upload = layui.upload;
        //执行实例
        var uploadInst = upload.render({
            elem: '#upload_content' //绑定元素
            ,url: '<?php echo url("Upload/file_images"); ?>' //上传接口
            ,done: function(res){
                //上传完毕回调
                if(res.code == 200){
                    $('.content_img').attr('src',res.data.src)

                }
            }
            ,accept: ''
            ,error: function(res){
                //请求异常回调
                console.log(res)
            }
        });
    });
</script>
</body>
</html>